import 'package:distribution_mall_flutter/constant/cf_constant.dart';
import 'package:distribution_mall_flutter/generated/l10n.dart';
import 'package:distribution_mall_flutter/widgets/modal_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class ModalNote extends ConsumerStatefulWidget {
  final String? text;
  final Function(String arg)? callback;
  const ModalNote({super.key, this.text, this.callback});

  @override
  ConsumerState createState() => _ModalNote();
}

class _ModalNote extends ConsumerState<ModalNote> {
  final _textEditingController = TextEditingController();

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      _textEditingController.text = widget.text ?? '';
    });
  }

  @override
  Widget build(BuildContext context) {
    return Material(
      child: EPModalButton(
          maxHeightScale: 0.8,
          buttonText: S.current.confirm,
          headerCrossAxis: CrossAxisAlignment.start,
          footerMargin:
              const EdgeInsets.symmetric(horizontal: EdgeConstant.edge218),
          hasDefaultFooter: true,
          onFooterPressed: () {
            if (widget.callback is Function) {
              widget.callback!(_textEditingController.value.text);
            }
          },
          title: S.current.Note,
          padding: const EdgeInsets.fromLTRB(0, 23.7, 0, EdgeConstant.edge10),
          children: [
            Container(
              height: 158,
              margin:
                  const EdgeInsets.symmetric(horizontal: EdgeConstant.edge20),
              child: TextField(
                controller: _textEditingController,
                // textAlign: TextAlign.left,
                maxLength: 200,
                maxLines: 5,
                minLines: 5,
                cursorColor: Color.fromRGBO(119, 119, 119, 1),
                // textAlignVertical: TextAlignVertical.center,
                decoration: InputDecoration(
                  filled: true,
                  fillColor: const Color.fromRGBO(221, 221, 221, 0.3),
                  hintText: S.current.please_enter,
                  errorBorder: const OutlineInputBorder(
                      borderSide: BorderSide(
                          color: Color.fromRGBO(255, 0, 0, 1), width: 0.9),
                      borderRadius: BorderRadius.all(
                          Radius.circular(RadiusConstant.edge8))),
                  focusedBorder: const OutlineInputBorder(
                      borderSide:
                          BorderSide(color: ColorConstant.grey233, width: 0.9),
                      borderRadius: BorderRadius.all(
                          Radius.circular(RadiusConstant.edge8))),
                ),
                keyboardType: TextInputType.text,
                style: const TextStyle(
                  fontSize: FontConstant.f16, // 设置字体大小为20
                ),
                onChanged: (str) {},
              ),
            )
          ]),
    );
  }
}
